package com.jy.modules.cims.component.image.task;

import java.util.Observer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jy.modules.cims.common.sysUtils.SpringContextUtils;
import com.jy.modules.cims.component.image.TransImagesObserver;
import com.jy.modules.cims.component.image.TransferImagesDto;
import com.jy.modules.cims.component.image.TransferImagesQueue;
import com.jy.modules.cims.component.image.service.DownImagesFromUrlService;

/**
 * @description 上传任务UploadImagesToFTPTask
 * @author shengzhoutao
 * @date 2015-09-29
 */
@Component
public class DownImagesFromUrlTask extends AbstractTransferImagesTask {
	@Autowired
	private SpringContextUtils springContextUtils;

	@Override
	public void doSomething() {

		// 控制队列处理个数
		if (TransferImagesQueue.zipQueue.size() > WAIT_QUEUE_SIZE || TransferImagesQueue.uploadQueue.size() > WAIT_QUEUE_SIZE) {
			sleep(1000 * 1 * 1);
			return;
		}

		TransferImagesDto transferImagesDto = getTransferImagesByQueue(TransferImagesQueue.downQueue);
		if (null == transferImagesDto) {
			sleep(EMPTY_QUEUE_SLEEP_MILLIS);
			return;
		} else {
			Observer observer = springContextUtils.getBean(TransImagesObserver.class);
			DownImagesFromUrlService observable = springContextUtils.getBean(DownImagesFromUrlService.class);
			observable.addObserver(observer);
			observable.doSomething(transferImagesDto);
		}
	}
}
